package com.duoec.magichour.enums;

import com.duoec.magichour.core.exceptions.BusinessException;
import com.duoec.magichour.dto.BaseResponse;

/**
 * 手机验证码类型
 * Created by ycoe on 17/7/4.
 */
public enum SmsMessageTypeEnum {
    /**
     * 注册，验证手机号码
     */
    MOBILE_CODE((byte) 0),

    /**
     * 重置密码
     */
    RESET_PWD((byte) 1);

    private byte code;

    SmsMessageTypeEnum(byte code) {
        this.code = code;
    }

    public byte getCode() {
        return code;
    }

    /**
     * 通过code获取枚举
     *
     * @param code
     * @return
     */
    public static SmsMessageTypeEnum getByCode(Byte code) {
        for (SmsMessageTypeEnum type : SmsMessageTypeEnum.values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        throw new BusinessException(BaseResponse.CODE_PARAM_INVALID, "暂不支持此种类型短信！");
    }
}
